package 剑指专题.位运算;


/*
 * Author：江松
 * Date：2023/4/2 10:03
 *
 数值的整数次方
 1,快速幂（二分）
 */

public class Main3 {
    public double Power(double base, int exponent) {
        boolean sign=exponent>=0;
        exponent=Math.abs(exponent);
        double res=1;
        while(exponent!=0){
            if((exponent&1)!=0){
                res*=base;
            }
            base*=base;
            exponent>>=1;
        }
        return sign?res:1/res;
    }
    /*
    //直接计算O(n)
    public double Power(double base, int exponent) {
        boolean sign=exponent>=0;
        double res=1;
        for(int i=0;i<Math.abs(exponent);++i){
            res*=base;
        }
        return sign?res:1/res;
    }
    */
}
